/*
 * DictManager.h
 *
 *  Created on: Jun 9, 2009
 *      Author: walter
 */

#ifndef DICTMANAGER_H_
#define DICTMANAGER_H_

#include <vector>
#include <iostream>
#include <map>
using namespace std;

#include <QSettings>
#include <QVariant>
#include <QString>
#include <QDir>
#include <QStringList>
//#include <QDomDocument>

#include "StaticModule.h"
#include "SQLiteDB.h"
#include "Word.h"

#define DM StaticModule<DictManager>::getInstance()

class QueryResult
{
public:
	QString mDictType;
	QString mDictName;
	QString mKey;
	QString mArticle;
	QString mFinalArticle;

	QueryResult(){}

	QueryResult(QString type, QString dictName, QString key, QString article):
		mDictType(type),
		mDictName(dictName),
		mKey(key),
		mArticle(article)
	{
	}

	QString getFinalArticle();
};

class DictInfo
{
public:
	QString mDictName;
	QString mDictType;
	QString mDictDescription;

	DictInfo(){}

	DictInfo(QString name, QString type, QString des):
		mDictName(name),
		mDictType(type),
		mDictDescription(des)
	{
	}
};

class Word;
class DictManager
{
public:
	DictManager();
	virtual ~DictManager();

	void readSettings();
	void writeSettings();

	void loadDicts();
	QStringList getDictList();
	QStringList getQueryDictList();
	QStringList getIgnorePhraseDictList();
	void setQueryDictList(vector<QString>& list);
	void setIgnorePhraseDictsList(vector<QString>& list);

	void lookup(Word* word);
	QString quickLookup(QString key); //used for one shot
	QStringList quickLookupThesaurus(QString key, QString dict);
	void setQueryResult(QString dictName, QString key, bool exactly);
	QString convertXdxf2Html(QString article);

private:
	QVector<QString> mQueryDicts; //Use these dictionaries.
	QVector<QString> mIgnorePhraseDicts; //Ignore phrase searched from these dictionaries
	QVector<QString> mDictDBs; //database files
	QVector<DictInfo> mDicts; //dictionaries names
	map<QString, QString> mDictMap; //map<dictName, dictDB>
	QVector<QueryResult> mQueryResult;

	QString xdxf_color_key;
	QString xdxf_color_co;
	QString xdxf_color_ex;
	QString xdxf_color_kref;
	QString xdxf_color_dtrn;
	QString xdxf_color_tense;
};

#endif /* DICTMANAGER_H_ */
